//
//  Macro.h
//  Pods

/** 常用宏定义 */

#ifndef Macro_h
#define Macro_h

#pragma mark - 尺寸
/** iPhone5 */
#define iPhone5 ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? CGSizeEqualToSize(CGSizeMake(640, 1136), [[UIScreen mainScreen] currentMode].size) : NO)

/** iPhone6 */
#define iPhone6 ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? CGSizeEqualToSize(CGSizeMake(750, 1334), [[UIScreen mainScreen] currentMode].size) : NO)

/** iPhone6+ */
#define iPhone6plus ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? (CGSizeEqualToSize(CGSizeMake(1125, 2001), [[UIScreen mainScreen] currentMode].size) || CGSizeEqualToSize(CGSizeMake(1242, 2208), [[UIScreen mainScreen] currentMode].size)) : NO)
/** iPhoneX */
#define iPhoneX ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? CGSizeEqualToSize(CGSizeMake(1125, 2436), [[UIScreen mainScreen] currentMode].size) : NO)

/* 屏幕尺寸 */
#define SCREEN_WIDTH ([UIScreen mainScreen].bounds.size.width)
#define SCREEN_HEIGHT ([UIScreen mainScreen].bounds.size.height)

/** 比例 */
#define SCALE_WIDTH [UIScreen mainScreen].bounds.size.width/375

#define AdaptX(x) (SCALE_WIDTH * x)

#define AdaptY(y) (SCALE_HEIGHT * y)

/** 如果是iPhoneX按照Plus 尺寸计算比例 */
#define SCALE_HEIGHT (iPhoneX ? 736.0/667 : [UIScreen mainScreen].bounds.size.height/667)
/** 适配IPhoneX相关 */
#define kNavMargin (iPhoneX ? 88 : 64)
#define kNavIPhoneX (iPhoneX ? 22 : 0)


#pragma mark - 颜色
/** RGB颜色 */
#define RGBCOLOR(r,g,b) [UIColor colorWithRed:(r)/255.0f green:(g)/255.0f blue:(b)/255.0f alpha:1]
/** RGB颜色透明度 */
#define RGBACOLOR(r,g,b,a) [UIColor colorWithRed:(r)/255.0f green:(g)/255.0f blue:(b)/255.0f alpha:(a)]
#define RGBSAMENUM(s)  [UIColor colorWithRed:(s)/255.f green:(s)/255.f blue:(s)/255.f alpha:1]
/** 哈希值颜色 */
#define ColorFromHex(rgbValue) [UIColor colorWithRed:((float)((rgbValue & 0xFF0000) >> 16))/255.0 green:((float)((rgbValue & 0xFF00) >> 8))/255.0 blue:((float)(rgbValue & 0xFF))/255.0 alpha:1.0]
/** 随机色 */
#define RandColor RGBCOLOR((arc4random()%255), (arc4random()%255), (arc4random()%255))

#pragma mark - UI
/**View圆角边框 颜色 */
#define ViewBorderRadius(View, Radius, Width, Color)\
\
[View.layer setCornerRadius:(Radius)];\
[View.layer setMasksToBounds:YES];\
[View.layer setBorderWidth:(Width)];\
[View.layer setBorderColor:[Color CGColor]]

/** View圆角 */
#define ViewRadius(View, Radius)\
[View.layer setCornerRadius:(Radius)];\
[View.layer setMasksToBounds:YES]

/** View 阴影 阴影颜色 阴影偏移量 阴影透明度,默认为0则看不到阴影 */
//如果maskToBounds ==YES则阴影效果看不到
#define ViewShadowColor(View, Color,Size,Opacity,Radius)\
\
[View.layer setShadowColor:([Color CGColor])];\
[View.layer setShadowOffset:(Size)];\
[View.layer setShadowOpacity:(Opacity)];\
[View.layer setShadowRadius:(Radius)]

/** Font */
#define Font(F) [UIFont systemFontOfSize:(F)]
#define AdaptFont(F) Font(AdaptX(F))
#define BoldFont(F) [UIFont boldSystemFontOfSize:(F)]
#define AdaptBoldFont(F) BoldFont(AdaptX(F))

/** Image */
#define ImageName(N) [UIImage imageNamed:N]
#define ImageOfFile(N) [UIImage imageWithContentsOfFile:N]



#pragma mark - 工具
/** 加载文件 */
#define LoadPath(name,type) [[NSBundle alloc] pathForResource:name ofType:type]
/** 加载XIB */
#define XIB(Class) [[[NSBundle mainBundle] loadNibNamed:NSStringFromClass([Class class]) owner:nil options:nil] firstObject]
/** 加载Storyboard */
#define SB(name) [[UIStoryboard storyboardWithName:name bundle:nil] instantiateInitialViewController]
/** 加载Storyboard id */
#define SB_ID(name, identifier)   [[UIStoryboard storyboardWithName:name bundle:nil] instantiateViewControllerWithIdentifier:identifier]

/** 检测block是否可用 */
#define Block_Exec(block, ...) if (block) { block(__VA_ARGS__); }

/** 生成一个weak的self对象 */
#define WeakSelf(type)  __weak typeof(type) weak##type = type
#define StrongSelf(type) __strong typeof(type) strong##type = type

/** 主window */
#define kKeyWindow  UIWindow *window  = [UIApplication sharedApplication].delegate.window

/** 检查系统版本 */
#define IOS_VERSION [[[UIDevice currentDevice] systemVersion] floatValue]

/** 角度转弧度 */
#define RADIAN(degrees) (M_PI * (degrees) / 180.0)

/** 弧度转角度 */
#define DEGREES(radian) (radian*180.0)/(M_PI)

/** 完美解决Xcode NSLog打印不全的宏 */
#ifdef DEBUG
#define QYLog(...) printf("[Line %d] %s %s\n",__LINE__,__PRETTY_FUNCTION__,[[NSString stringWithFormat:__VA_ARGS__]UTF8String]);
#else
#define QYLog(format, ...)
#endif

#endif /* Macro_h */
